<template>
	<view class="album-page">
		<cu-custom class="nav-bar" :isBack="false" :bgImgBlur="bgimg"  content="肖战">
		</cu-custom>
		<scroll-view scroll-y="true" class="page-content" @scroll="scrollpage" :style="{top:customBar*2+'rpx'}" >
			<view class="album-top">
				<view class="bg" :style="'background-image:url(' + bgimg + ')'"></view>
				<view class="bg1"></view>
				<view class="album-con">
					<view class="flex-box">
						<view class="img-info">
							<image class="img" :src="bgimg"></image>
						</view>
						<view class="info-con flex-item">
							<view class="title">{{ album.name }}</view>
							<view class="desc-box flex-box">
								<view class="desc">{{ album.description}}</view>
							</view>
						</view>
					</view>
				</view>
			</view>
			<view class="album-list">
				<view class="title-bar flex-box">
					<view class="play">
						<text class="iconfont">&#xe710;</text>
						播放全部
					</view>
				</view>
				<mu-list :list="targetMuList" :isNav="false"></mu-list>
			</view>
		</scroll-view>
	</view>
</template>

<script>
	function debounce(fn, wait = 10) {    
		var timeout = null;    
		return function() {        
			if(timeout !== null) clearTimeout(timeout);        
			timeout = setTimeout(fn, wait);    
		}
	}
var that = null
import { getMuListDetail } from '@/apis/music.js';
import muList from '@/components/musiclist.vue'
export default {
	data() {
		return {
			album: {},
			bgimg:'',
			playList: [],
			scrollTop: 20,
			scrollY: 0
		};
	},
	components:{
		muList
	},
	computed:{
		targetMuList(){
			if(!this.album.tracks) return [];
			const t = this.album.tracks.slice(0,25);
			return t.map(val=>{
				return{
					id:val.id,
					name:val.name,
					picUrl:val.al.picUrl,
					n1:val.ar[0].name,
					n2:val.al.name
				}
			})
		},
		customBar(){
			return this.CustomBar
		}
	},
	created() {
		that = this
	},
	onLoad(options) {
		this.getData(6788789766);
	},
	methods: {
		getData(id) {
			const par = {
				id
			};
			getMuListDetail(par).then(res => {
				// res.playlist.description = res.playlist.description.slice(0, 27)
				const album = res.playlist;
				this.bgimg = album.backgroundCoverUrl || album.coverImgUrl
				this.album = album;
				this.playList = res.privileges;
			});
		},
		scrollpage (e) {
			this.scrollY = e.detail.scrollTop
			this.scroll()
		},
		// 设置背景条
		scroll: debounce(() => {
			if (that.scrollY < 5) {
				that.scrollTop = 20
			} else {
				if (that.scrollY < 300) {
					that.scrollTop = - parseInt(that.scrollY) + 20
				}
			}
		}),
		goBack () {  // 返回上一页
			uni.navigateBack();
		}
	}
};
</script>

<style lang="scss" scoped>
$bgheight: 550rpx;
$bgtop: -44px;
	
.nav-bar{
	position: relative;
	background-position: 0 0px;
	background-repeat: no-repeat;
	background-size: cover;
}

.bg {
	position: absolute;
	top: 0;
	left: 0;
	height: 100%;
	width: 100%;
	filter: blur(35px);
	background-position: 0 0px;
	background-repeat: no-repeat;
	background-size: cover;
}
.bg1 {
	position: absolute;
	top: 0;
	left: 0;
	height: 100%;
	width: 100%;
	background: rgba(0, 0, 0, 0.2);
	z-index: 2;
}

.page-content {
	position: fixed;
	left: 0;
	right: 0;
	bottom: 0;
}
.album-top {
	position: relative;
	top: $bgtop;
	height: $bgheight;
	padding-top:44px;
	overflow: hidden;
	background: #fff;
	.bg{
		background-size: 100%;
	}
	.album-con {
		position: absolute;
		width: 100%;
		padding: 46rpx 24rpx 0 30rpx;
		z-index: 10;
	}
}
.album-bot {
	padding-top: 42rpx;
	color: #fff;
	text-align: center;
	.iconfont {
		font-size: 44rpx;
	}
}
.img-info {
	position: relative;
	width: 280rpx;
	height: 280rpx;
	margin-right: 40rpx;
	border-radius: 10rpx;
	overflow: hidden;
	&:before {
		content: ' ';
		position: absolute;
		left: 0;
		top: 0;
		width: 100%;
		height: 40rpx;
		z-index: 2;
		background-image: linear-gradient(180deg, rgba(0, 0, 0, 0.2), transparent);
	}
	.img {
		width: 280rpx;
		height: 280rpx;
	}
	.count {
		position: absolute;
		top: 0;
		right: 0;
		padding-left: 25rpx;
		line-height: 34rpx;
		color: #fff;
		font-size: 24rpx;
		z-index: 10;
		background: url()
			no-repeat;
		background-size: 25rpx 25rpx;
		transform: scale(0.8);
	}
}
.info-con {
	.title {
		margin-bottom: 14rpx;
		color: #fff;
		line-height: 46rpx;
		font-weight: 600;
	}
}
.avator-box {
	margin-bottom: 26rpx;
	align-items: center;
	color: #ccc0ba;
	font-size: 25rpx;
	.avator {
		width: 60rpx;
		height: 60rpx;
		margin-right: 12rpx;
		border-radius: 60rpx;
	}
}
.desc-box {
	align-items: center;
	line-height: 40rpx;
	color: #ccc0ba;
	font-size: 23rpx;
}
.album-list {
	position: relative;
	top:- 84px;
	background: #fff;
	border-radius: 36rpx 36rpx 0 0;
	z-index: 100;
	.title-bar{
		padding:10rpx;
		justify-content: space-between;
		.iconfont{
			margin-left: 16rpx;
			margin-right: 16rpx;
			font-size: 40rpx;
		}
		.play{
			line-height: 80rpx;
			color:#252621;
			font-weight: 600;
			font-size: 32rpx;
		}
		.collect{
			width:228rpx;
			height:80rpx;
			text-align: center;
			line-height: 80rpx;
			border-radius: 80rpx;
			color:#fff;
			background: #fb2b21;
		}
	}
	.item {
		align-items: center;
		height: 120rpx;
	}
	.con {
		padding-right: 40rpx;
		align-items: center;
		justify-content: space-between;
	}
	.num {
		width: 84rpx;
		text-align: center;
		line-height: 120rpx;
		color: #999;
		font-size: 24rpx;
		&.on {
			color: #ff3a3a;
		}
	}
	.tit {
		margin-right: 20rpx;
		color: #333;
		line-height: 48rpx;
		font-size: 32rpx;
	}
	.count {
		margin-right: 20rpx;
		color: #ccc;
		line-height: 48rpx;
		font-size: 24rpx;
		transform: scale(0.84);
	}
	.icon {
		width: 56rpx;
		height: 20rpx;
	}
	.desc {
		color: #999;
		font-size: 24rpx;
		line-height: 40rpx;
	}
}
</style>

